﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace TotalApplication.AngelSix
{
    [ValueConversion(typeof(string), typeof(BitmapImage))]
    public class HeaderToImageConverter : IValueConverter
    {
        /// <summary>
        /// the only instance of <see cref="HeaderToImageConverter"/>
        /// </summary>
        public static HeaderToImageConverter Instance { get; } = new HeaderToImageConverter();  

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string path = (string)value;
            if (path == null)
                return null;

            var image = "/assets/img/文件.png";

            if (path.LastIndexOf('\\') == path.Length - 1)
            {
                image = "/assets/img/文件关闭.png";
            }
            else if (new FileInfo(path).Attributes.HasFlag(FileAttributes.Directory))
            {
                image = "/assets/img/文件夹.png";
            }
            else if(new FileInfo(path).Attributes.HasFlag(FileAttributes.Hidden))
            {
                image = "/assets/img/evil.png";
            }

            return new BitmapImage(new Uri($"pack://application:,,,{image}"));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
